package org.kjtc.controller;

import org.apache.log4j.Logger;
import org.kjtc.entity.*;
import org.kjtc.service.WeChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ConfigController {
    private static Logger logger = Logger.getLogger(ConfigController.class);
    @Autowired
    private WeChartService weChartService;

    @RequestMapping("/searchSystemConfig")
    @ResponseBody
    public Map<String, Object> searchSystemConfig() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<SystemConfig> configList = null;
        try {
            configList  = weChartService.searchSystemConfig();
            map.put("wechatConfigMsg", configList);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("wechatConfigMsg", "Error");
            return map;
        }
        return map;
    }

    @RequestMapping(value = "/updateSystemConfig")
    @ResponseBody
    public Map<String, Object> updateSystemConfig(SystemConfig systemConfig) {
        Map<String, Object> map = new HashMap<String, Object>();
        systemConfig.setUpdateUser("swk");
        try {
            weChartService.updateSystemConfig(systemConfig);
            map.put("result", "Success");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("result", "Error");
            return map;
        }
        return map;
    }
}
